/**
 * Thinking in java 
 *  2018/08/01
 */
package com.dzb.aio;

import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.CompletionHandler;


/**
 * @author dzb
 * @date 2018年8月15日 下午5:24:03
 * @description  
 * @version 1.0.0
 */
public class AcceptCompletionHandler implements CompletionHandler<AsynchronousSocketChannel, AsyncTimeServerHandler>{

	public void completed(AsynchronousSocketChannel result,AsyncTimeServerHandler attachement){
		attachement.asynchronousServerSocketChannel.accept(attachement,this);
		ByteBuffer buffter = ByteBuffer.allocate(1024);
		//read 参数 channel 读取数据包   channel 携带附件  回调参数使用   接收回调业务的handle 
		result.read(buffter, buffter, new ReadCompletionHandler(result));
	}
	
	//失败处理
	public void failed(Throwable exc,AsyncTimeServerHandler attachement){
		exc.printStackTrace();
		attachement.latch.countDown();
	}

	
	
}
